import fs from "fs";
import path from "path";
import dealSvg from "./dealSvgUtil";
// 要处理的svg文件夹路径
const targetDirs = [path.join(__dirname, '../../images'), path.join(__dirname, '../../../../manage/src/assets'), path.join(__dirname, '../../../../mobile/src/assets'), path.join(__dirname, '../../../../pc/src/assets'),];
const traverseDir = (dir) => {
  try {
    const files = fs.readdirSync(dir);
    files.forEach((file) => {
      const filePath = path.join(dir, file);
      const stat = fs.statSync(filePath);
      if (stat.isDirectory()) {
        traverseDir(filePath);
        //递归子目录
      } else if (path.extname(filePath) === '.svg') {
        dealSvg(filePath);
      }
    });
  } catch (e) {
    console.error(`目录不存在 ${dir} :`, e);
  }
};
targetDirs.forEach((targetDir) => {
  if (fs.existsSync(targetDir)) {
    traverseDir(targetDir);
  } else {
    console.error(`目录不存在 ${targetDir} :`);
  }
});


